package face.pay.message.handler.event;

import face.pay.dao.CpnCardDetailInfoDao;
import face.pay.entity.CpnCardDetailInfo;
import face.pay.message.entity.event.UserConsumeCardEvent;
import face.pay.message.handler.AbstractHandler;
import face.pay.util.DateUtil;
import face.pay.util.bean.JavaBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
@Slf4j
public class UserConsumeCardEventHandler extends AbstractHandler {

    @Autowired
    CpnCardDetailInfoDao cpnCardDetailInfoDao;

    @Override
    public Boolean doEvent(Map<String, String> map) {

        log.info("优惠券核销");
        UserConsumeCardEvent userConsumeCardEvent = (UserConsumeCardEvent)JavaBeanUtils.mapToBeanWithSupper(map,UserConsumeCardEvent.class);

        String cardId   = userConsumeCardEvent.getCardId();

        String cardCode = userConsumeCardEvent.getUserCardCode();
        String outerStr = userConsumeCardEvent.getOuterStr();



        CpnCardDetailInfo cpnCardDetailInfo =  new CpnCardDetailInfo();

        cpnCardDetailInfo.setCode(cardCode);
        cpnCardDetailInfo.setStatus(4);
        cpnCardDetailInfo.setWxCardId(cardId);
        /**
         * 核销时间
         */
        String consumeTime  = DateUtil.dateFormat(new Date());
        cpnCardDetailInfo.setConsumeTime(consumeTime);

        /**
         * 更新状态
         */
        this.cpnCardDetailInfoDao.updateByWxCardIdAndCode(cpnCardDetailInfo);
        return true;
    }
}
